<template>
  <box-card>
    <div slot="operator">
      <!--      <el-button class="op-btn" icon="el-icon-plus" size="mini" type="primary" @click="handleAdd">新增</el-button>-->
    </div>
    <el-form slot="search" ref="queryForm" inline :model="queryParams" label-suffix="：" size="small">
      <el-form-item label="岗位名称" prop="name">
        <el-input v-model="queryParams.name" clearable placeholder="请输入岗位名称" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" type="info" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table slot="content" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
<!--      <el-table-column align="center" type="selection" width="55"/>-->
      <el-table-column label="名称" min-width="100px" prop="name" show-overflow-tooltip/>
      <el-table-column label="地址" min-width="150px" prop="addr" show-overflow-tooltip/>
      <el-table-column label="备注" min-width="120px" prop="remark" show-overflow-tooltip/>
<!--      <el-table-column class-name="small-padding fixed-width" fixed="right" label="操作" min-width="150">-->
<!--        <template v-if="scope.row.id !== 1" v-slot:default="scope">-->
<!--          <el-button icon="el-icon-s-promotion" size="mini" type="text" @click="handleLink(scope.row)">访问-->
<!--          </el-button>-->
<!--          <el-button icon="el-icon-edit" size="mini" type="text" @click="handleEdit(scope.row)">修改-->
<!--          </el-button>-->
<!--          <el-button slot="reference" icon="el-icon-delete" size="mini" type="text" @click="handleDelete(scope.row)">-->
<!--            删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <pagination slot="page" v-show="pageParam.total > 0" :limit.sync="pageParam.pageSize" :page.sync="pageParam.pageNum"
                :total="pageParam.total" @pagination="getList"/>
  </box-card>
</template>

<script>
import {list} from "@/api/base";

export default {
  name: "UserPostCard",
  props: {
    userId: String,
  },
  data() {
    return {
      id: undefined,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      multiple: true,
      // 遮罩层
      loading: true,
      baseUrl: "/system/user/post/",
      dataList: [],
      queryParams: {},
      pageParam: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
    }
  },
  created() {
    if (this.userId === undefined) {
      console.log(this.$store)
      this.userId = this.$store.state.id
    }
    this.resetQuery();
  },
  methods: {
    getList() {
      this.loading = true;
      list(this.baseUrl, {
        ...this.queryParams,
        userId: this.userId,
        pageNum: this.pageParam.pageNum,
        pageSize: this.pageParam.pageSize
      }).then((response) => {
        this.dataList = response.rows;
        this.pageParam.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  }
}
</script>

<style lang="scss" scoped>
</style>
